package com.test.consumer.model;

import java.io.Serializable;

/**
 * @see 数据返回对象 RestData.java gome.com.cn
 * @copyright 2018年2月5日 下午2:39:19
 * @author jiangdabin
 */
/**
 * @ClassName: RestData
 * @Description: TODO
 * @author chengcheng 1294480405@qq.com
 * @date 2018年4月18日 下午3:38:07
 */
public class RestData implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    /**
     * 状态码
     */
    private String code;
    
    /**
     * 数据结果
     */
    private Object data;
    
    /**
     * 操作是否成功
     */
    private boolean success;
    
    /**
     * 消息
     */
    private String message;
    
    /* 异常信息 */
    private String exceptionMsg;
    
    public RestData() {
        
    }
    
    private RestData(MessageCode messageCode) {
        if (messageCode == null) {
            return;
        }
        this.success = messageCode.getSuccess();
        this.code = messageCode.getCode();
        this.message = messageCode.getMessage();
    }
    
    public static RestData make(MessageCode messageCode) {
        return new RestData(messageCode);
    }
    
    public static RestData make(MessageCode messageCode, String msg) {
        RestData result = new RestData(messageCode);
        result.setMessage(msg);
        return result;
    }
    
    /**
     * 返回默认成功对象
     * 
     * @param data 返回的数据
     * @return
     */
    public static RestData makeSuccess(Object data) {
        RestData result = new RestData(MessageCode.SUCCESS);
        result.setData(data);
        return result;
    }
    
    /**
     * <b>设置信息</b>
     * <p>
     * </p>
     * 
     * @param msg 返回的msg ,非data
     * @return
     */
    public static RestData makeSuccess(String msg) {
        RestData result = new RestData(MessageCode.SUCCESS);
        result.setMessage(msg);
        return result;
    }
    
    /**
     * <b></b>
     * <p>
     * </p>
     * 
     * @param data
     * @param isData 内容是否为的内容
     * @return
     */
    public static RestData makeSuccess(String data, boolean isData) {
        RestData result = new RestData(MessageCode.SUCCESS);
        result.setData(data);
        return result;
    }
    
    public static RestData makeSuccess() {
        RestData result = new RestData(MessageCode.SUCCESS);
        return result;
    }
    
    /**
     * 返回默认的对象
     * 
     * @param data 要返回的参数
     * @param code 状态码
     * @return
     */
    public static RestData makeSuccessCode(Object data, String code) {
        RestData result = new RestData(MessageCode.SUCCESS);
        result.setCode(code);
        result.setData(data);
        return result;
    }
    
    /**
     * 返回成功的对象
     * 
     * @param data 要返回的参数
     * @param msg 提示信息
     * @return
     */
    public static RestData makeSuccess(Object data, String msg) {
        RestData result = new RestData(MessageCode.SUCCESS);
        result.setData(data);
        result.setMessage(msg);
        return result;
    }
    
    /**
     * 返回成功的对象
     * 
     * @param data 要返回的参数
     * @param code 状态码
     * @param msg 提示信息
     * @return
     */
    public static RestData makeSuccess(Object data, String code, String msg) {
        RestData result = new RestData(MessageCode.SUCCESS);
        result.setCode(code);
        result.setData(data);
        result.setMessage(msg);
        return result;
    }
    
    /**
     * 返回失败的默认对象
     * 
     * @param data 返回的数据
     * @return
     */
    public static RestData makeError(Object data) {
        RestData result = new RestData(MessageCode.FAILED);
        result.setData(data);
        return result;
    }
    
    public static RestData makeError(String msg) {
        RestData result = new RestData(MessageCode.FAILED);
        result.setMessage(msg);
        return result;
    }
    
    public static RestData makeError() {
        RestData result = new RestData(MessageCode.FAILED);
        return result;
    }
    
    /**
     * 返回失败的默认的对象
     * 
     * @param data 要返回的参数
     * @param code 状态码
     * @return
     */
    public static RestData makeErrorCode(Object data, String code) {
        RestData result = new RestData(MessageCode.FAILED);
        result.setCode(code);
        result.setData(data);
        return result;
    }
    
    /**
     * 返回失败的默认的对象
     * 
     * @param data 要返回的参数
     * @param msg 提示信息
     * @return
     */
    public static RestData makeError(Object data, String msg) {
        RestData result = new RestData(MessageCode.FAILED);
        result.setData(data);
        result.setMessage(msg);
        return result;
    }
    
    /**
     * 返回失败的默认对象
     * 
     * @param data 要返回的参数
     * @param code 状态码
     * @param msg 提示信息
     * @return
     */
    public static RestData makeError(Object data, String code, String msg) {
        RestData result = new RestData(MessageCode.FAILED);
        result.setCode(code);
        result.setData(data);
        result.setMessage(msg);
        return result;
    }
    
    public String getCode() {
        return code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    public Object getData() {
        return data;
    }
    
    public void setData(Object data) {
        this.data = data;
    }
    
    public boolean getSuccess() {
        return success;
    }
    
    public void setSuccess(boolean success) {
        this.success = success;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String msg) {
        this.message = msg;
    }
    
    public String getExceptionMsg() {
        return exceptionMsg;
    }
    
    public void setExceptionMsg(String exceptionMsg) {
        this.exceptionMsg = exceptionMsg;
    }
    
    @Override
    public String toString() {
        return "RestData [code=" + code + ", data=" + data + ", success=" + success + ", msg=" + message + ", exceptionMsg=" + exceptionMsg + "]";
    }
    
}
